package com.zbl.zblproject.wxpublichao.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zbl.zblproject.wxpublichao.entity.ApplicationLetter;
import com.zbl.zblproject.wxpublichao.entity.Fk;
import com.zbl.zblproject.wxpublichao.entity.Jm;
import com.zbl.zblproject.wxpublichao.mapper.ApplicationLetterMapper;
import com.zbl.zblproject.wxpublichao.mapper.FkMapper;
import com.zbl.zblproject.wxpublichao.mapper.JmMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2019/4/29
 */
@Api(tags = "微信公众号接口")
@RestController
@RequestMapping("/wxpublichao")
public class WxPublicHaoController {
    @Autowired
    private JmMapper jmMapper;

    @Autowired
    private FkMapper fkMapper;

    @Autowired
    private ApplicationLetterMapper applicationLetterMapper;


    @PostMapping("/insert-jm")
    @ApiOperation("新增加盟用户信息")
    public String insertJm(@RequestBody String jm){
        int i =0;
        i = jmMapper.insert(json(jm));
        if (i>0){
            return "200";
        }else {
            return "500";
        }
    }

    @PostMapping("/insert-fk")
    @ApiOperation("新增用户反馈信息")
    public String insertFk(@RequestBody String fk){
        int i =0;
        i= fkMapper.insert(json2(fk));
        if (i>0){
            return "200";
        }else {
            return "500";
        }
    }

    @PostMapping("/insert-yp")
    @ApiOperation("新增应聘用户信息")
    @ResponseBody
    public String insertYp(@RequestBody String yp){
    int i =0;
    i=applicationLetterMapper.insert(json1(yp));
    if (i>0){
        return "200";
    }else {
        return "500";
    }
    }

    public Jm json(String a){
        JSONObject array = JSONObject.parseObject(a);
        Jm jm = new Jm();
        JSONObject aa = JSONObject.parseObject(array.getString("jm"));
        jm.setCity(aa.getString("city"));
        jm.setPhone(aa.getString("phone"));
        jm.setSource(aa.getString("source"));
        jm.setUsername(aa.getString("username"));
        return jm;
    }

    public ApplicationLetter json1(String a){
        JSONObject array = JSONObject.parseObject(a);
        JSONObject aa = JSONObject.parseObject(array.getString("yp"));
        ApplicationLetter yp = new ApplicationLetter();
        yp.setPhone(aa.getString("phone"));
        yp.setJob(aa.getString("job"));
        yp.setUsername(aa.getString("username"));
        return yp;
    }

    public Fk json2(String a){
        JSONObject array = JSONObject.parseObject(a);
        JSONObject aa = JSONObject.parseObject(array.getString("fk"));
        Fk fk = new Fk();
        fk.setPhone(aa.getString("phone"));
        fk.setUsername(aa.getString("username"));
        fk.setMessage(aa.getString("message"));
        return fk;
    }
}
